<?php
class elementForm extends ClFormModel
{
    public $Etitle;
    public $Etype;
    public $Edefault;
    public $Esubject;
    public $Eorder;
    //表单验证规则
    public function rules()
    {
        return array(
            array('Etitle,Etype,Edefault,Esubject','required'),
            array('Eorder','safe'),
        );
    }

    //字段标签
    public function attributeLabels()
    {
        return array(
            'Etitle'=>'字段标题',
            'Etype'=>'字段类型',
            'Edefault'=>'字段默认值',
            'Epid'=>'对应模板id',
            'Esubject'=>'字段主体',
            'Eorder'=>'排序'
        );
    }

    //添加
    public function add($pid)
    {
        $game = new element();
        $game->Etitle=$this->Etitle;
        $game->Etype=$this->Etype;
        $game->Esubject=$this->Esubject;
        $game->Edefault=$this->Edefault;
        $game->Epid=$pid;
        $game->Eorder=$this->Eorder;
        if($game->save()){
            return true;
        }else{
            return false;
        }

    }

    //修改
    public function edit($id)
    {
        $game = element::model()->findByPk($id);
        $game->Etitle=$this->Etitle;
        $game->Etype=$this->Etype;
        $game->Esubject=$this->Esubject;
        $game->Edefault=$this->Edefault;
        $game->Eorder=$this->Eorder;
        //保存关键字
        if($game->save()){
            return true;
        }else{
            return false;
        }
    }
}